package com.atguigu.lease.web.app.custom.inteceptors;

import com.atguigu.lease.common.exception.LeaseException;
import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.common.utils.JwtUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * @BelongsProject: lease
 * @BelongsPackage: com.atguigu.lease.web.admin.custom.inteceptors
 * @Author: 王席舒
 * @CreateTime: 2024-10-12  09:52
 * @Description: TODO
 * @Version: 1.0
 */

//加入到ioc容器
@Component
public class AuthenticationInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("access_token");
        //判断是否有令牌
        if(token == null){
            //没有证明没有登陆
            throw new LeaseException(ResultCodeEnum.APP_LOGIN_AUTH);
        }

        JwtUtil.parseToken(token);
        return true;
    }
}
